home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / libs / pdcurs21 / private / _copywin.c < prev    next >
C/C++ Source or Header  |  1993-06-20  |  2KB  |  104 lines

  1. #define    CURSES_LIBRARY    1
  2. #include <curses.h>
  3.  
  4. #ifdef PDCDEBUG
  5. char *rcsid__copywin = "$Header: C:\CURSES\private\RCS\_copywin.c 2.1 1993/06/18 20:22:57 MH Rel MH $";
  6. #endif
  7.  
  8.  
  9.  
  10.  
  11. /*man-start*********************************************************************
  12.  
  13.   PDC_copy_win()    - Common routine for copywin(), overlay() and overwrite()
  14.      functions.
  15.  
  16.   PDCurses Description:
  17.      This function copies the region of the source window specified
  18.      over the specified region of the destination window. All validation
  19.      of limits are done by the calling function.
  20.  
  21.      Thanks to Andreas Otte (venn@uni-paderborn.de) for the code changes.
  22.  
  23.   PDCurses Errors:
  24.      ERR is returned if either src or dst windows are NULL;
  25.  
  26.   Portability:
  27.      PDCurses    int    PDC_copy_win( WINDOW* src_w, WINDOW* dst_w
  28.              int src_tr,int src_tc,int src_br,int src_bc,
  29.              int dst_tr,int dst_tc,int dst_br,int dst_bc,bool overlay);
  30.  
  31. **man-end**********************************************************************/
  32.  
  33. int    PDC_copy_win(WINDOW *src_w, WINDOW *dst_w,
  34.              int src_tr,int src_tc,int src_br,int src_bc,
  35.              int dst_tr,int dst_tc,int dst_br,int dst_bc,bool overlay)
  36. {
  37.     int*    minchng;
  38.     int*    maxchng;
  39.     chtype*    w1ptr;
  40.     chtype*    w2ptr;
  41.     int    col;
  42.     int    line;
  43.     int    xdiff = src_bc - src_tc;
  44.     int    ydiff = src_br - src_tr;
  45.     int    y1;
  46.  
  47. #ifdef PDCDEBUG
  48.     if (trace_on) PDC_debug("PDC_copy_win() - called\n");
  49. #endif
  50.  
  51.     if (src_w == (WINDOW *)NULL)    return( ERR );
  52.     if (dst_w == (WINDOW *)NULL)    return( ERR );
  53.  
  54.     minchng    = dst_w->_firstch;
  55.     maxchng    = dst_w->_lastch;
  56.  
  57.  
  58.     for (y1 = 0; y1 < dst_tr; y1++)
  59.         {
  60.         minchng++;
  61.         maxchng++;
  62.         }
  63.  
  64.     for (line = 0; line < ydiff; line++)
  65.     {
  66.         register int fc;
  67.         register int lc;
  68.  
  69.         w1ptr = src_w->_y[line+src_tr]+src_tc;
  70.         w2ptr = dst_w->_y[line+dst_tr]+dst_tc;
  71.         fc    = _NO_CHANGE;
  72.  
  73.         for (col = 0; col < xdiff; col++)
  74.         {
  75.             if ((*w1ptr) != (*w2ptr)
  76.             &&  !((*w1ptr & A_CHARTEXT) == src_w->_blank && overlay))
  77.             {
  78.                 *w2ptr = *w1ptr;
  79.                 if (fc == _NO_CHANGE)
  80.                 {
  81.                     fc = col+dst_tc;
  82.                 }
  83.                 lc = col+dst_tc;
  84.             }
  85.             w1ptr++;
  86.             w2ptr++;
  87.         }
  88.  
  89.         if (*minchng == _NO_CHANGE)
  90.         {
  91.             *minchng = fc;
  92.             *maxchng = lc;
  93.         }
  94.         else    if (fc != _NO_CHANGE)
  95.         {
  96.             if (fc < *minchng)    *minchng = fc;
  97.             if (lc > *maxchng)    *maxchng = lc;
  98.         }
  99.         minchng++;
  100.         maxchng++;
  101.     }
  102.     return( OK );
  103. }
  104.